<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2018 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: http://www.dsxcms.com
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2018/9/18
 * Time: 下午3:37
 */

namespace App\Library\User;


use App\Library\AuthenticatedUser;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

trait UserManagers
{
    use AuthenticatedUser;

    /**
     * @param Request $request
     * @return mixed
     */
    public function storeAuth(Request $request)
    {
        $newauth = Arr::only($request->input('auth', []),[
            'name',
            'id_card_no',
            'id_card_front',
            'id_card_back',
            'id_card_hand'
        ]);

        $newauth['auth_state'] = 0;
        $auth = $this->user()->auth->update($newauth);
        return $this->savedAuthSuccess($request, $auth);
    }

    /**
     * @param Request $request
     * @param $auth
     * @return \Illuminate\Http\JsonResponse
     */
    protected function savedAuthSuccess(Request $request, $auth)
    {
        return ajaxReturn(['auth'=>$auth]);
    }
}
